﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_Flow_GetReceiver_V2]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_Flow_GetReceiver_V2];
GO
CREATE PROCEDURE [dbo].[sproc_Flow_GetReceiver_V2]
    @DocID int
AS
BEGIN
SET NOCOUNT ON;

SELECT
        S.*,
        P.Position_ID,
        P.Position_name
    FROM 
        dbo.UDS_Staff S
        INNER JOIN dbo.UDS_Staff_In_Position SIP ON S.Staff_ID = SIP.Staff_ID
        INNER JOIN dbo.UDS_Position P ON SIP.Position_ID = P.Position_ID
    WHERE
        S.Staff_ID IN
        (    
            SELECT staff_id
                FROM dbo.UDS_Flow_Status
                WHERE doc_id = @DocID
        );

END
GO
